package com.itqf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/10
 * @Time: 下午4:36
 */
public class MyAdvice implements MethodBeforeAdvice,AfterReturningAdvice,MethodInterceptor {
    @Override
    public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println("开启事务|打印日志......"+method.getName()
                +"---"+Arrays.toString(objects)+"--"+o);
    }



    @Override
    public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {
        System.out.println("提交事务|打印日志......"+method.getName()
                +"---"+Arrays.toString(objects)+"--"+o);

    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        System.out.println("环绕--前置增强----"+methodInvocation.getMethod().getName());
        //执行（调用）被代理对象的方法
        Object  result = methodInvocation.proceed();

        System.out.println("环绕--后置增强----"+methodInvocation.getMethod().getName());
        return result;
    }
}
